module TerminalKeynote
  class Line
    attr_accessor :string, :align

    DEFUALT_ALIGN = :center

    def initialize(options={})
      @string = options[:string]
      @align = options[:align] || DEFUALT_ALIGN
    end

    def width
      @string.chomp.ansi_strip.length
    end

    def left_margin
      case @align
      when :left
        margin = 1
      when :right
        margin = Window.width - width
      when :center
        margin = (Window.width - width) / 2
      end

      [1, margin].max
    end

    def to_s
      string
    end

    def ==(other)
      string == other.string
    end
  end
end
